﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NFinal.Advanced;

namespace WebApplication1.DDD.Web.Default.users
{
    public class insertAction  : Controller
	{
		#if (!AspNET && !MicrosoftOwin && !NFinalOwin)
		public insertAction(HttpContext context):base(context){}
		public insertAction(Microsoft.Owin.IOwinContext context):base(context){}
		public insertAction(NFinal.Owin.HtmlWriter writer,NFinal.Owin.Request request):base(writer,request){}
		#endif
		#if AspNET
		public insertAction(HttpContext context):base(context){}
		#endif
		#if MicrosoftOwin
		public insertAction(Microsoft.Owin.IOwinContext context):base(context){}
		#endif
		#if NFinalOwin
		public insertAction(string fileName, NFinal.Owin.Request request, NFinal.CompressMode compressMode) :base(fileName,request,compressMode){}
		public insertAction(System.IO.Stream stream,NFinal.Owin.Request request, NFinal.CompressMode compressMode) : base(stream,request,compressMode) {}
		public insertAction(System.Collections.Generic.IDictionary<string, object> enviroment, NFinal.Owin.Request request, NFinal.CompressMode compressMode):base(enviroment,request,compressMode){}
		#endif
		public insertAction(Controller controller):base(controller){}
        
        
        [GetJson("users/show.aspx")]
        public void insert(Models.Entity.Common.users user)
        {
            
var con = new System.Data.SQLite.SQLiteConnection(NFinal.Config.ConfigurationManager.ConnectionStrings["Common"].ConnectionString);
con.Open();

            
#region	var count; 插入并返回ID
			var __insert_count_command__ = new System.Data.SQLite.SQLiteCommand("insert into users(name,pwd) values(@user_name,@user_pwd);select last_insert_rowid();", con);
						var __insert_count_parameters__=new System.Data.SQLite.SQLiteParameter[2];
			
			__insert_count_parameters__[0] = new System.Data.SQLite.SQLiteParameter("@user_name",System.Data.DbType.String,2147483647);
			__insert_count_parameters__[0].Value = user.name.WithDBNull();
			__insert_count_parameters__[1] = new System.Data.SQLite.SQLiteParameter("@user_pwd",System.Data.DbType.String,2147483647);
			__insert_count_parameters__[1].Value = user.pwd.WithDBNull();
						__insert_count_command__.Parameters.AddRange(__insert_count_parameters__);
							var count = __insert_count_command__.ExecuteScalar().AsVar();
			__insert_count_command__.Dispose();
			#endregion
			
            con.Close();
            AjaxReturn(count > 0);
        }

        
    }
}